#!/usr/bin/env python
import os
import shutil

need_cygwin_hack = False
natural_docs = os.path.join(os.path.abspath('thirdparty'), 'all', 'NaturalDocs', 'NaturalDocs')
if not hasattr(os, 'uname'):
	if os.path.exists('C:\\cygwin\\bin\\bash.exe'):
		need_cygwin_hack = True
		#cwd = os.path.abspath('.')
		#cwd = cwd.replace('\\', '/')
		natural_docs = '/'.join(['thirdparty', 'all', 'NaturalDocs', 'NaturalDocs'])
		natural_docs = 'C:\\cygwin\\bin\\bash.exe -c "' + natural_docs

input_dirs = ['api']
output_dir = 'docs'
project_dir = '.naturalDocs'

def natural_docs_command(target,source,env):
	args = [natural_docs]
	args += ["-i"]
	for d in source: args += [d.name]
	args += ['-o', 'HTML', str(target[0])]
	args += ['-p', project_dir]
	print ' '.join(args), "\n"
	os.mkdir('docs')
	os.mkdir('.naturalDocs')
	cmd = ' '.join(args)
	if need_cygwin_hack: cmd += '"'
	os.system(cmd)
	shutil.rmtree('.naturalDocs')

env = Environment()
docs = env.Command(output_dir, input_dirs, natural_docs_command)
